package com.dongliu.dao;

import com.dongliu.domain.Book;
import com.dongliu.domain.LentRecord;
import com.dongliu.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

// TODO 添加@Mapper
@Mapper
public interface UserDao {

    @Insert("insert into user values(null, #{username}, #{password}, #{name}, #{age}, #{sex}, #{tel}, #{limitNumber}, #{lentNumber}, #{money})")
    public int save(User user);

    @Update("update user set username=#{username}, password=#{password}, name=#{name}, age=#{age}, sex=#{sex}, tel=#{tel}, limitNumber=#{limitNumber}, lentNumber=#{lentNumber}, money=#{money} where username=#{username}")
    public int update(User user);

    @Update("update user set username=#{username}, password=#{password}, name=#{name}, age=#{age}, sex=#{sex}, tel=#{tel}, limitNumber=#{limitNumber}, lentNumber=#{lentNumber} where id=#{id}")
    public int updateById(User user);

    @Delete("delete from user where username=#{username}")
    public int delete(String username);

    @Select("select * from user where username=#{username}")
    public User getByUsername(String username);

    @Select("select * from user where id=#{id}")
    public User getById(Integer id);

    @Select("select * from user")
    public List<User> getAll();

    @Select("select count(*) from user")
    public int getCount();

    @Select("select * from user where username=#{username} and password=#{password}")
    public User login(String username, String password);
}

